package com.th.supcom.pds.impl.service.internal;

import java.util.List;

import net.carefx.framework.exception.BusinessException;
import net.carefx.framework.translate.TranslatorManager;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.th.supcom.pds.domain.vo.PdsPackageInfoVO;
import com.th.supcom.pds.impl.manager.PdsSupplyPackageManager;
import com.th.supcom.pds.internal.api.PdsSupplyPackageService;

public class PdsSupplyPackageServiceImpl implements PdsSupplyPackageService
{

    /**
     * 最终修改人员.
     */
    public static final String SCC_LAST_MODIFIER_NAME = "$Author$";

    /**
     * 最终版本号.
     */
    public static final String SCC_REVISION = "$Revision$";

    private PdsSupplyPackageManager m_pdsSupplyPackageManager;
    private TranslatorManager m_translatorManager;

    public void setTranslatorManager (TranslatorManager translatorManager)
    {

        m_translatorManager = translatorManager;
    }

    @Override
    public int findPdsPackageInfoVOCountByName (final String name)
    {
        PdsSupplyPackageServiceImpl.s_logger.debug ("进入findPdsPackageInfoVOCountByName方法,入参:" + name);
        int count = 0;
        try
        {
            count = m_pdsSupplyPackageManager.findPdsPackageInfoVOCountByName (name);
        }
        catch (final Exception e)
        {
            PdsSupplyPackageServiceImpl.s_logger.error (e.getMessage ());
            e.printStackTrace ();
            throw new BusinessException (e.getMessage (), e);
        }
        return count;

    }

    @Override
    public List <PdsPackageInfoVO> findPdsPackageInfoVOWithPageByName (final int offset, final int limit, final String name)
    {
        PdsSupplyPackageServiceImpl.s_logger.debug ("进入findPdsPackageInfoVOWithPageByName方法,入参:");
        List <PdsPackageInfoVO> pdsPackageInfoVO = null;
        try
        {
            pdsPackageInfoVO = m_pdsSupplyPackageManager.findPdsPackageInfoVOWithPageByName (offset, limit, name);
        }
        catch (final Exception e)
        {
            PdsSupplyPackageServiceImpl.s_logger.error (e.getMessage ());
            throw new BusinessException (e.getMessage (), e);
        }
        pdsPackageInfoVO = m_translatorManager.translate (pdsPackageInfoVO);
        return pdsPackageInfoVO;

    }

    public void setPdsSupplyPackageManager (PdsSupplyPackageManager pdsSupplyPackageManager)
    {

        m_pdsSupplyPackageManager = pdsSupplyPackageManager;
    }

    @Override
    public void addPdsPackageInfo (PdsPackageInfoVO vo)
    {
        s_logger.debug ("进入addPdsPackageInfo方法,入参:" + vo);
        if (vo == null)
        {
            throw new BusinessException ("插入数据为空!");
        }
        try
        {
            Long serialNo = m_pdsSupplyPackageManager.getSequence ();
            vo.setSerialNo (serialNo);
            m_pdsSupplyPackageManager.addPdsPackageInfo (vo);
        }
        catch (Exception e)
        {
            s_logger.error (e.getMessage ());
            throw new BusinessException ("插入数据失败", e);
        }

    }

    @Override
    public void removePdsPackageInfoByList (List <Long> serialNoList)
    {
        s_logger.debug ("进入removePdsPackageInfoByList方法,入参:" + serialNoList);
        try
        {
            m_pdsSupplyPackageManager.removePdsPackageInfoByList (serialNoList);
        }
        catch (Exception e)
        {
            s_logger.error (e.getMessage ());
            e.printStackTrace ();
            throw new BusinessException ("删除数据失败" + e.getMessage (), e);
        }

    }

    @Override
    public void modifyPdsPackageInfoByExample (PdsPackageInfoVO pdsPackageInfoVO)
    {
        s_logger.debug ("进入modifyPdsPackageInfoByExample方法,入参:");

        try
        {
            m_pdsSupplyPackageManager.modifyPdsPackageInfoByExample (pdsPackageInfoVO);
        }
        catch (Exception e)
        {
            s_logger.error (e.getMessage ());
            e.printStackTrace ();
            throw new BusinessException ("更新失败" + e.getMessage (), e);
        }

    }

    /**
     * 公司版权信息.
     */
    public static final String copyright = "Copyright 2014, Carefx Corporation";

    /**
     * 日志记录器.
     */
    private static final Logger s_logger = LoggerFactory.getLogger (PdsSupplyPackageServiceImpl.class);

    /**
     * 提交路径.
     */
    public static final String SCC_BRANCH = "$URL$";
    /**
     * 提交日期.
     */
    public static final String SCC_LAST_MODIFICATION_DATE = "$Date$";
}
